import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:dio/dio.dart' as MyDio;

main() {
  // runApp(MaterialApp(home: StatelessHome()));
  runApp(GetMaterialApp(home: StatelessHome()));
}

class StatelessHome extends StatelessWidget {
  const StatelessHome({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('bar'),
      ),

      // body: ElevatedButton(
      //   onPressed: () {
      //     Get.snackbar('QQ', '您收到了一条群组消息', icon: Icon(Icons.message),
      //         borderRadius: 10);
      //   },
      //   child: Text('click me'),
      // ),

      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          ElevatedButton(
              onPressed: () {
                _getHttp();
              },
              child: Text('get')),
          ElevatedButton(onPressed: _postHttp, child: Text('post')),
        ],
      ),
    );
  }

  void _getHttp() async {
    MyDio.Dio dio = MyDio.Dio();
    MyDio.Response rsp =
        await dio.get('https://jsonplaceholder.typicode.com/posts/1');
    print(rsp.data.toString());
  }

  void _postHttp() async {
    MyDio.Dio dio = MyDio.Dio();
    // 表单数据
    MyDio.FormData formData = MyDio.FormData.fromMap(
        {'id': 1, 'name': 'GUO', 'email': 'guo@gmail.com'});
    MyDio.Response rsp = await dio.post(
        'https://jsonplaceholder.typicode.com/posts',
        data: {'no': 12, 'name': 'dio'});
    print(rsp.data.toString());
  }
}
